package com.variometer.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by michal.kudlacak on 7/13/13.
 */
public class SynchronizedObservable implements Observable {
    private final List<Observer> observers=new ArrayList<Observer>();
    @Override
    public void addObserver(Observer observer) {
        synchronized (observers){
            observers.add(observer);
        }
    }

    @Override
    public void removeObserver(Observer observer) {
        synchronized (observers){
            observers.remove(observer);
        }
    }

    @Override
    public void notifyObservers(Observable model) {
        synchronized (observers){
            for (Observer observer: observers)
                observer.onChange(model);
        }

    }
}
